<template>
  <div class="nav-bg" :class="{navScroll: scrollDirection}"></div>

  <theme-nav class="theme-nav" :class="{navScroll: scrollDirection}"></theme-nav>

  <router-view class="content-wrapper"></router-view>

</template>

<script>
import { throttle } from 'lodash';

import ThemeNav from '@/components/ThemeNav.vue'

export default {
  components: {
    ThemeNav,
  },
  data() {
    return {
      scrollDirection: false,
    }
  },
  mounted() {
    let beforeY = 0;
    document.addEventListener('scroll', throttle(() => {
      if(window.scrollY - beforeY > 0) {
        this.scrollDirection = true;
      } else {
        this.scrollDirection = false;
      }
      beforeY = window.scrollY
    }, 200));
  }
}
</script>

<style scoped lang="less">
.nav-bg {
  position: fixed;
  z-index: 8888;
  top: 0;
  width: 100vw;
  height: 130px;
  background-color: var(--bgColor);
  transition: .3s;
}

.theme-nav {
  --themeNavHeight: 60px;
  --themeNavWidth: var(--innerWidth);
  z-index: 8888;
  position: fixed;
  top: calc(var(--topNavHeight) + 10px);
  left: 0;
  right: 0;
  margin: 0 auto;
  transition: .2s;
}

.content-wrapper {
  margin: 140px auto;
  display: flex;
  justify-content: space-between;
  width: var(--innerWidth);
}
</style>